package com.cheli.servicebase.config.exceptionhandler;


import com.cheli.commonutils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Auther: cl
 * @Date: 2020/9/30 16:07
 * @Description:
 */
@ControllerAdvice
@ResponseBody@Slf4j
public class GlobalExceptionHandler {

   @ExceptionHandler(Exception.class)
    public R error(Exception e){
        e.printStackTrace();
        return R.error().message("系统异常，请稍后再试");
    }

   @ExceptionHandler(ArithmeticException.class)
    public R error(ArithmeticException e){
        e.printStackTrace();
        return R.error().message("ArithmeticException异常处理");
    }

   @ExceptionHandler(MyException.class)
    public R error(MyException e){
        e.printStackTrace();
        log.error(e.getMsg());
        return R.error().code(e.getCode()).message(e.getMsg());
    }
}
